package com.sq.shangcheng.controller;

import com.sq.shangcheng.result.CodeMsg;
import com.sq.shangcheng.result.Result;
import com.sq.shangcheng.vo.LoginVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Controller
@RequestMapping("/login")
public class LoginController {

	private static Logger log = LoggerFactory.getLogger(LoginController.class);

    @RequestMapping("/index")
    public String toLogin() {
        return "login";
    }

    @RequestMapping("/login")
    @ResponseBody
    public Result<String> login(HttpServletResponse response, @Valid LoginVo loginVo) {
        if(loginVo !=null){
            if(!"13588000000".equals(loginVo.getMobile())){
                return Result.error(CodeMsg.MOBILE_NOT_EXIST);
            }
            if(!"5c4fcc5add5d087de1e8534189c687f7".equals(loginVo.getPassword())){
                return Result.error(CodeMsg.PASSWORD_ERROR);
            }
        }
        System.out.println("用户登录成功!");
        return Result.success("登录成功!");
    }


    @RequestMapping("/logout")
    @ResponseBody
    public Result<String> doLogout(HttpServletResponse response, HttpServletRequest request) {
        //注销
        System.out.println("用户注销成功!");
        return Result.success("注销成功!");
    }

}
